﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Reservering : System.Web.UI.Page
{
    DB db = new DB();


    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] == null)
        {
            Response.Redirect("Default.aspx");
        }
        if (!IsPostBack)
        {
            BindData();
        }
    }

    public void BindData()
    {
        string sql = string.Format("Select TransactieID,TransactieHeader.FilmNaam,Tijd,Zaal,Rang,Status from TransactieHeader,FilmTijden WHERE TransactieHeader.FilmTijdID=FilmTijden.ID");
        SqlDataAdapter da = new SqlDataAdapter(sql, db.GetConnection());
        DataTable dt = new DataTable();
        da.Fill(dt);
        Grid.DataSource = dt;
        Grid.DataBind();
    }


    protected void btnZoek_Click(object sender, EventArgs e)
    {
        DataTable dt = db.getReserveringen(txtZoek.Text);
        Grid.DataSource = dt;
        Grid.DataBind();

    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindData();
    }
    protected void Grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection con = db.GetConnection();
        SqlCommand cmd = new SqlCommand();

        if (((LinkButton)Grid.Rows[0].Cells[7].Controls[0]).Text == "Annuleer")
        {
            cmd.CommandText = "DELETE FROM TransactieHeader WHERE TransactieID=@id";
            cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(Grid.Rows[e.RowIndex].Cells[0].Text);
        }
        else
        {
            cmd.CommandText = "UPDATE TransactieDetail SET Status='Betaald'";
            cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(Grid.Rows[e.RowIndex].Cells[0].Text);
        }
        cmd.Connection = con;
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();

        BindData();

    }



    
}